<template>
    <!-- 小程序端自定义顶部栏（已适配顶部刘海屏） -->
    <view class="cu-custom" :class="isfixed ? 'cu-custom-fixed' : 'cu-custom-stciky'" :style="{ background: bgColor }">
        <view class="cu-bar" :style="StatusBar">
            <slot name="freebar" />
        </view>
    </view>
</template>

<script>
export default {
    name: "NavigationBar",
    props: {
        isfixed: {
            type: Boolean,
            default: false
        },
        bgColor: {
            type: String,
            default: ""
        }
    },
    data() {
        return {
            CustomBarHeight: 65,
            StatusBarHeight: 20
        };
    },

    computed: {
        StatusBar() {
            let style = {};
            style["height"] = this.CustomBarHeight + "px";
            style["padding-top"] = this.StatusBarHeight + "px";
            return style;
        }
    },
    created() {
        // 获取胶囊高度，配置导航高度
        const systemInfo = uni.getSystemInfoSync();
        this.CustomBarHeight =
            systemInfo.platform === "android" ? systemInfo.statusBarHeight + 50 : systemInfo.statusBarHeight + 45;
        this.StatusBarHeight = systemInfo.statusBarHeight;
        // #ifdef MP-ALIPAY
        this.CustomBarHeight = systemInfo.statusBarHeight;
        this.StatusBarHeight = systemInfo.statusBarHeight + systemInfo.titleBarHeight;
        // #endif
    }
};
</script>

<style>
.cu-custom {
    display: block;
}
.cu-custom-fixed {
    position: fixed;
    width: 100%;
    z-index: 99999;
    top: 0;
    left: 0;
}
.cu-custom-stciky {
    position: sticky;
    top: 0;
    z-index: 100;
}
.cu-custom .cu-bar .content {
    width: calc(100% - 440rpx);
}
/* #ifdef MP-ALIPAY */
.cu-custom .cu-bar .action .cuIcon-back {
    opacity: 0;
}

/* #endif */

.cu-custom .cu-bar .content image {
    height: 60rpx;
    width: 240rpx;
}

.cu-custom .cu-bar {
    min-height: 0px;
    box-shadow: 0rpx 0rpx 0rpx;
    z-index: 9999;
}

.cu-custom .cu-bar .border-custom {
    position: relative;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 1000rpx;
    height: 30px;
}

.cu-custom .cu-bar .border-custom::after {
    content: " ";
    width: 200%;
    height: 200%;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: inherit;
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
    box-sizing: border-box;
    border: 1rpx solid #ffffff;
    opacity: 0.5;
}

.cu-custom .cu-bar .border-custom::before {
    content: " ";
    width: 1rpx;
    height: 110%;
    position: absolute;
    top: 22.5%;
    left: 0;
    right: 0;
    margin: auto;
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
    box-sizing: border-box;
    opacity: 0.6;
    background-color: #ffffff;
}

.cu-custom .cu-bar .border-custom text {
    display: block;
    flex: 1;
    margin: auto !important;
    text-align: center;
    font-size: 34rpx;
}
</style>
